package com.street.controller.user;

import com.street.dto.CartDTO;
import com.street.entity.Cart;
import com.street.result.Result;
import com.street.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/cart")
public class CartController {
    @Autowired
    CartService cartService;

    @GetMapping("/list")
    public Result<List<Cart>> list(Long shopId){
        List<Cart>cartList=cartService.list(shopId);
        return Result.success(cartList);
    }

    @PostMapping("/add")
    public Result add(@RequestBody CartDTO cartDTO){
        cartService.add(cartDTO);
        return Result.success();
    }

    @PostMapping("/sub")
    public Result subCart(@RequestBody CartDTO cartDTO){
        cartService.delete(cartDTO);
        return Result.success();
    }
    @DeleteMapping("/clear")
    public Result clearCart(Long shopId){
        cartService.clear(shopId);
        return Result.success();
    }
}
